﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawner : MonoBehaviour
{
    [Header("生成流体种类")]
    public ElementState elementState;
    /*  [Header("tile边长")]
      public float edgeLength;
      [Header("填充间隔")]
      public float interval;
      [Header("水粒子")]
      public GameObject root;
      /// <summary>
      /// 球体半径
      /// </summary>
      private float radius;
      private Vector2 startPoi;
      private Vector2 endPoi;
      private void Awake()
      {
          this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + 50, 0);
          radius=root.GetComponent<CircleCollider2D>().radius*root.transform.localScale.x;
          startPoi = new Vector2();
          endPoi = new Vector2();
          this.gameObject.SetActive(false);
      }
      private void OnEnable()
      {
          var t = this.transform.position;
          startPoi.x = t.x - (edgeLength / 2);
          startPoi.y = t.y + (edgeLength / 2);
          endPoi.x = t.x + (edgeLength / 2);
          endPoi.y = t.y - (edgeLength / 2);
          Fill(startPoi,endPoi,elementState);

      }
      /// <summary>
      /// 填充矩形
      /// </summary>
      void Fill(Vector2 start,Vector2 end,ElementState element)
      {
          Vector2 nowPoi = new Vector2();
          nowPoi.x = start.x + radius;
          nowPoi.y = start.y - radius;
          while (nowPoi.x < endPoi.x - radius)
          {
              FluidProcessSubmodule.instance.Create(element, nowPoi);
              nowPoi.x += 2*radius + interval+Random.Range(-5*interval,5*interval);
          }
          if ((nowPoi.x >= endPoi.x - radius) && (nowPoi.y <= endPoi.y + radius))
          {
              return;
          }
          else
          {
              start.y -=2*radius + interval;
              Fill(start, end, element);
          }
      }*/
    public void Awake()
    {
        //this.gameObject.SetActive(false);
    }
    public void OnEnable()
    {
        var nowPos = this.transform.position;
        FluidProcessSubmodule.instance.Create(elementState, nowPos);
    }
}
